package com.htl.io.缓冲流;

import java.io.*;

/**
 *  文件类型的复制
 */

public class 文件复制2 {
    public static void main(String[] args) {
        InputStream inputStream = null;
        BufferedInputStream bufferedInputStream = null;
        OutputStream outputStream = null;
        BufferedOutputStream bufferedOutputStream = null;

        try {
            inputStream = new FileInputStream("D:\\Project\\IDEA_project\\java_note\\src\\com\\htl\\io\\java1\\idea.png");
            bufferedInputStream = new BufferedInputStream(inputStream);
            outputStream = new FileOutputStream("D:\\Project\\IDEA_project\\java_note\\src\\com\\htl\\io\\java2\\idea2.png");
            bufferedOutputStream = new BufferedOutputStream(outputStream);
            int temp = 0;
            // 读
            while (((temp = bufferedInputStream.read()) != -1)) {
                // 写
                bufferedOutputStream.write(temp);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                bufferedOutputStream.flush();
                bufferedOutputStream.close();
                outputStream.close();
                bufferedInputStream.close();
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
